package com.java110.mall.goods.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.shop.ShopDistributionModeDto;
import com.java110.po.shop.ShopDistributionModePo;
import com.java110.mall.goods.bmo.shopDistributionMode.IDeleteShopDistributionModeBMO;
import com.java110.mall.goods.bmo.shopDistributionMode.IGetShopDistributionModeBMO;
import com.java110.mall.goods.bmo.shopDistributionMode.ISaveShopDistributionModeBMO;
import com.java110.mall.goods.bmo.shopDistributionMode.IUpdateShopDistributionModeBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/shopDistributionMode")
public class ShopDistributionModeApi {

    @Autowired
    private ISaveShopDistributionModeBMO saveShopDistributionModeBMOImpl;
    @Autowired
    private IUpdateShopDistributionModeBMO updateShopDistributionModeBMOImpl;
    @Autowired
    private IDeleteShopDistributionModeBMO deleteShopDistributionModeBMOImpl;

    @Autowired
    private IGetShopDistributionModeBMO getShopDistributionModeBMOImpl;

    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopDistributionMode/saveShopDistributionMode
     * @path /app/shopDistributionMode/saveShopDistributionMode
     */
    @RequestMapping(value = "/saveShopDistributionMode", method = RequestMethod.POST)
    public ResponseEntity<String> saveShopDistributionMode(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "modeId", "请求报文中未包含modeId");
        Assert.hasKeyAndValue(reqJson, "modeName", "请求报文中未包含modeName");
        Assert.hasKeyAndValue(reqJson, "productId", "请求报文中未包含productId");


        ShopDistributionModePo shopDistributionModePo = BeanConvertUtil.covertBean(reqJson, ShopDistributionModePo.class);
        return saveShopDistributionModeBMOImpl.save(shopDistributionModePo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopDistributionMode/updateShopDistributionMode
     * @path /app/shopDistributionMode/updateShopDistributionMode
     */
    @RequestMapping(value = "/updateShopDistributionMode", method = RequestMethod.POST)
    public ResponseEntity<String> updateShopDistributionMode(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shopModeId", "请求报文中未包含shopModeId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "modeId", "请求报文中未包含modeId");
        Assert.hasKeyAndValue(reqJson, "modeName", "请求报文中未包含modeName");
        Assert.hasKeyAndValue(reqJson, "productId", "请求报文中未包含productId");


        ShopDistributionModePo shopDistributionModePo = BeanConvertUtil.covertBean(reqJson, ShopDistributionModePo.class);
        return updateShopDistributionModeBMOImpl.update(shopDistributionModePo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopDistributionMode/deleteShopDistributionMode
     * @path /app/shopDistributionMode/deleteShopDistributionMode
     */
    @RequestMapping(value = "/deleteShopDistributionMode", method = RequestMethod.POST)
    public ResponseEntity<String> deleteShopDistributionMode(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "shopId不能为空");

        Assert.hasKeyAndValue(reqJson, "shopModeId", "shopModeId不能为空");


        ShopDistributionModePo shopDistributionModePo = BeanConvertUtil.covertBean(reqJson, ShopDistributionModePo.class);
        return deleteShopDistributionModeBMOImpl.delete(shopDistributionModePo);
    }

    /**
     * 微信删除消息模板
     *
     * @param shopId 小区ID
     * @return
     * @serviceCode /shopDistributionMode/queryShopDistributionMode
     * @path /app/shopDistributionMode/queryShopDistributionMode
     */
    @RequestMapping(value = "/queryShopDistributionMode", method = RequestMethod.GET)
    public ResponseEntity<String> queryShopDistributionMode(@RequestParam(value = "shopId") String shopId,
                                                            @RequestParam(value = "page") int page,
                                                            @RequestParam(value = "row") int row) {
        ShopDistributionModeDto shopDistributionModeDto = new ShopDistributionModeDto();
        shopDistributionModeDto.setPage(page);
        shopDistributionModeDto.setRow(row);
        shopDistributionModeDto.setShopId(shopId);
        return getShopDistributionModeBMOImpl.get(shopDistributionModeDto);
    }
}
